package com.cxx.purchasecharge.core.model.persistence;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.cxx.purchasecharge.core.model.BaseModel;

/**
 * 账单项
 */
@Entity
@Table (name = "pc_order_item")
public class OrderItem extends BaseModel
{
    private static final long serialVersionUID = 1L;

    private long id;
    private float unitPrice;
    private int amount;
    private float sum;
    private String comment;

    private Goods goods;
    private Order order;
    
    public OrderItem () {}

    @Id
    @GeneratedValue (strategy = GenerationType.AUTO)
    public long getId ()
    {
        return id;
    }

    public void setId (long id)
    {
        this.id = id;
    }

    @OneToOne (optional = false)
    @JoinColumn (name = "goods_id")
    public Goods getGoods ()
    {
        return goods;
    }

    public void setGoods (Goods goods)
    {
        this.goods = goods;
    }

    @Column (nullable = false)
    public float getUnitPrice ()
    {
        return unitPrice;
    }

    public void setUnitPrice (float unitPrice)
    {
        this.unitPrice = unitPrice;
    }

    @Column (nullable = false)
    public int getAmount ()
    {
        return amount;
    }

    public void setAmount (int amount)
    {
        this.amount = amount;
    }

    @Column (nullable = false)
    public float getSum ()
    {
        return sum;
    }

    public void setSum (float sum)
    {
        this.sum = sum;
    }

    @Column (length = 2048)
    public String getComment ()
    {
        return comment;
    }

    public void setComment (String comment)
    {
        this.comment = comment;
    }

    @ManyToOne (fetch = FetchType.LAZY, cascade =
    { CascadeType.REFRESH })
    @JoinColumn (name = "order_id")
    public Order getOrder ()
    {
        return order;
    }

    public void setOrder (Order order)
    {
        this.order = order;
    }

}
